package com.sample.base.ui.activity

import android.view.View
import android.widget.AdapterView
import android.widget.ArrayAdapter
import com.loyal.helper.UIHelper
import com.sample.base.base.BaseActivity
import com.sample.base.databinding.ActivityVbBinding

class VBActivity : BaseActivity(), AdapterView.OnItemClickListener {
    private val binding by lazy { ActivityVbBinding.inflate(layoutInflater) }
    private val toolbarBinding by lazy{ binding.toolbar }

    override fun setLayoutOrView() {
        setContentView(binding.root)
    }

    override fun afterOnCreate() {
        val array = arrayOf("1", "3", "5").asList()
        toolbarBinding.toolbar.title = "ViewBinding"
        setSupportActionBar(toolbarBinding.toolbar)
        binding.listView.adapter = ArrayAdapter(
            this,
            android.R.layout.simple_dropdown_item_1line,
            array
        )
        binding.listView.onItemClickListener = this
    }

    override fun onItemClick(parent: AdapterView<*>?, view: View, position: Int, id: Long) {
        val item = parent?.adapter?.getItem(position)
        if (position / 2 == 0) UIHelper.toastShort(this, "$item:short")
        else UIHelper.toastShort(this, "$item:long")
    }
}